#ifndef findcircle_H
#define findcircle_H


#include "shape.h"

#include "shapebase.h"
#include "imagebase.h"

#include<vector>
#include<list>

using namespace std;

class findobject;
typedef std::vector<int> ListVector;
typedef std::list<int> intList;

typedef struct qedge
{
  QPointF m_pointA;
  QPointF m_pointB;
  int m_itype;//0 output 1 edge
}QEdge;
typedef std::vector<qedge> qedges;

class findcircle:public QShape
{
public:
    findcircle();
    ~findcircle();

    int thre();

    void clear();
    void setshow(int ishow);
    void setcircle(double ix,double iy,double iw);
    void sethcircle(double ix,double iy,double ix0,double iy0);
    void seticircle(double ix,double iy,double ix0,double iy0);
    void setpart(int ipart0,int ipart1);

     virtual void setrect(int ix,int iy,int iw,int ih);
    virtual void drawshape(QPainter &painter,QPalette &pal);
    void drawshapex(QPainter &painter,QPalette &pal,double dmovx,double dmovy,
                    double dangle,double dzoomx,double dzoomy);

    void drawpattern(QPainter &painter);
    void drawpatternx(QPainter &painter,
                      double dmovx,double dmovy,
                      double dangle,
                      double dzoomx,double dzoomy);
    void edgepattern(ImageBase &image);
    void setcomparegap(int igap);
    void patternzeroposition();
    void savepatternfile(const char * pchar);
    void loadpatternfile(const char * pchar);
    QRectF patternboundingrect();
    void patternrootgrid(double itype,double drate,double ilevel);
    void patternzoom(double dx,double dy,double igap,double itype);
    void patterntranform(int igap,int itype,int isgap,int iline);
    void patternrotate(double dangle);
    void modelzoom(double dx,double dy);
    void patterngap2gap(int inewgap);
    QPainterPath &getpatternpath();
    PointsShape &getpattern();
    void setpattern(PointsShape &apattern){m_modelpoints=apattern;}

    void setpart(double dpart0,double dpart1, double dsap);
    void SetWHgap(double  dwrate,double dhrate);
    void measure(void *pimage);
    void search(void *pimage);

    void setsearchdir(int idir);
    void findpattern(void *pimage);

    void setlinesamplerate(double dsamplerate);
    void setlinegap(int igap);
    void setmethod(int imethod);
    void setthre(int ithre);
    void setgamarate(int igama);
    void setfindsetting(int ifindset);
    void setfilter(int ifilterborw,int ifiltermin,int ifiltermax);//21 w ,22 b
    void setselectedgenum(int iedgenum);

    void setshowlines(int ilines){m_ishowlines=ilines;}
    PointsShape &getresultpointsw();
    void Measure(ImageBase &image);
    void Search(ImageBase &image);
    void shapesetroi(void *pshape);
    void findroadkey();
    int getconparegap(){return m_icomparegap;}
private:
    int m_icomparegap;
    PointsShape m_modelpoints;    //red(white 1) gap blue(black 0) model

    PointsShape m_measurepointsA;

    PointsShape m_measurepointsA_;

    ImageBase * g_pbackimage;

    findobject * g_pbackfindobject;

    PointsShape m_measurepoints;

    qedges m_edges;
   // PointsShape m_measurepoints_h;

    QPoint m_centpoint;
    PointsShape m_circle;

    PointsShape m_circleA;
    PointsShape m_circleB;

    PointsShape m_partA;
    PointsShape m_partB;


    PointsShape m_keymap;
    PointsShape m_seekmap;

   // LineShape m_LineA;
   // LineShape m_LineB;

    LineVector m_lines;
    ListVector m_validnums;
    ListVector m_disvalidnums;

    int m_searchdir=0;
   // LineVector m_lines_h;

    double m_dwrate;
    double m_drate;
    double m_dpartrate;

    QPoint* m_listscanorA;
    QPoint* m_listcollectorA;

    int m_iSelectPointGap;
    int m_iMethod;
    int m_iThreshold;
    int m_igamarate;
    double m_dsamplerate;

    int m_ifindset;
    int m_ifilterborw;//21 w ,22 b ,23
    qint64 m_ifiltermax;
    qint64 m_ifiltermin;

    int m_iselectedgenum;
    int m_ineedfixs;

    int m_ncurscan;
    int m_nscansize;

    int resultsize();



    static int m_curfindcirclenum;

    int m_ishowlines;
    QRectF m_measurepointsboundingRect;
 public:
    void easycluster(int igapx=10,int igapy=10 ,int iclusternum=5);
    QRectF measurepointsboundingrect(){return m_measurepointsboundingRect;}

};


#endif
